package com.lichengGongshang.common;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.lichengGongshang.controller.*;

/**
 * Created by dulong on 2015/12/20.
 */
public class JFConfig extends JFinalConfig {

    public void configConstant(Constants me) {
        loadPropertyFile("a_little_config.txt");
        //配置模板
        me.setViewType(ViewType.JSP);
        me.setEncoding("UTF-8");
        me.setDevMode(getPropertyToBoolean("devMode", false));
    }

    public void configRoute(Routes me) {
        me.add("/", MainController.class );

    }

    public void configPlugin(Plugins me) {
        //配置数据库连接信息
        DruidPlugin dp = new DruidPlugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"));
        dp.addFilter(new StatFilter());
        WallFilter wall = new WallFilter();
        wall.setDbType("mysql");
        dp.addFilter(wall);
        me.add(dp);

        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
        me.add(arp);

        arp.setShowSql(true);

    }

    public void configInterceptor(Interceptors me) {}

    public void configHandler(Handlers me) {
        me.add(new ContextPathHandler("base"));
    }

    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 8080, "/", 5);
    }
}
